package com.jikedaquan.game.jwt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jikedaquan.game.jwt.entity.Relation;
import com.jikedaquan.game.jwt.entity.User;
import com.jikedaquan.game.jwt.mapper.RelationMapper;
import com.jikedaquan.game.jwt.service.RelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 好友关系 服务实现类
 * </p>
 *
 * @author jiake
 * @since 2019-10-31
 */
@Service
public class RelationServiceImpl extends ServiceImpl<RelationMapper, Relation> implements RelationService {

    @Override
    public List<Relation> getAllRelation(User user) {
        //获取当前用户的好友
        Map<String,Object> params = new HashMap<>();
        params.put("user_id", user.getId());
        params.put("status","2");
        QueryWrapper<Relation> queryWrapper = new QueryWrapper<Relation>()
                .allEq(params)
                .orderByAsc("create_time");
        List<Relation> relations = baseMapper.selectList(queryWrapper);
        return relations;
    }

    @Override
    public boolean insertRelation(Relation relation) {
        if (relation != null){
            //插入好友请求
            int result = baseMapper.insert(relation);
            return result ==1;
        }else{
            return false;
        }

    }

    @Override
    public boolean updateRelation(Relation relation) {
        if (relation != null){
            //根据id修改好友状态
            int result = baseMapper.updateById(relation);
            return result ==1;
        }else{
            return false;
        }
    }
}
